quaternion Derived Type

type, public :: quaternion

Defines a quaternion of the form:


Contents


Components

Type Visibility Attributes Name Initial
real(kind=real64), public :: w

The real component of the quaternion.

real(kind=real64), public :: x

The first element in the imaginary component of the quaternion.

real(kind=real64), public :: y

The second element in the imaginary component of the quaternion.

real(kind=real64), public :: z

The third element in the imaginary component of the quaternion.


Constructor

public interface quaternion

  • private pure function quat_init_array(x) result(rst)

    Constructs a quaternion from a 4-element array stored such that [w, x, y, z].

    Arguments

    Type IntentOptional Attributes Name
    real(kind=real64), intent(in), dimension(4) :: x

    The array from which to initialize the quaternion stored in the order [w, x, y, z].

    Return Value type(quaternion)

    The resulting quaternion.

  • private pure function quat_init_angle_axis(angle, axis) result(rst)

    Constructs a quaternion given an axis and the angle of rotation about the axis.

    Arguments

    Type IntentOptional Attributes Name
    real(kind=real64), intent(in) :: angle

    The rotation angle, in radians.

    real(kind=real64), intent(in), dimension(3) :: axis

    A 3-element vector defining the axis about which the rotation occurrs.

    Return Value type(quaternion)

    The resulting quaternion.

  • private pure function quat_init_mtx(r) result(rst)

    Constructs a quaternion from a 3-by-3 rotation matrix using the Stanley method.

    Arguments

    Type IntentOptional Attributes Name
    real(kind=real64), intent(in), dimension(3, 3) :: r

    The rotation matrix.

    Return Value type(quaternion)

    The resulting quaternion.


Type-Bound Procedures

procedure, public :: normalize => quat_normalize

  • private pure subroutine quat_normalize(q)

    Normalizes the quaternion.

    Arguments

    Type IntentOptional Attributes Name
    class(quaternion), intent(inout) :: q

    On input, the quaternion to normalize. On output, the normalized quaternion.

procedure, public :: to_angle_axis => quat_to_angle_axis

  • private pure subroutine quat_to_angle_axis(q, angle, axis)

    Converts the quaternion to the equivalent angle-axis form.

    Arguments

    Type IntentOptional Attributes Name
    class(quaternion), intent(in) :: q

    The quaternion.

    real(kind=real64), intent(out) :: angle

    The rotation angle, in radians.

    real(kind=real64), intent(out) :: axis(3)

    The axis of rotation.

procedure, public :: to_array => quat_to_vec4

  • private pure function quat_to_vec4(q) result(rst)

    Converts a quaternion to a 4-element array of the form [w, x, y, z].

    Arguments

    Type IntentOptional Attributes Name
    class(quaternion), intent(in) :: q

    The quaternion.

    Return Value real(kind=real64), dimension(4)

    The array of the form [w, x, y, z].

procedure, public :: to_matrix => quat_to_matrix

  • private pure function quat_to_matrix(q) result(rst)

    Converts the quaternion to a 3-by-3 rotation matrix.

    Arguments

    Type IntentOptional Attributes Name
    class(quaternion), intent(in) :: q

    The quaternion.

    Return Value real(kind=real64), dimension(3,3)

    The resulting rotation matrix.

procedure, public :: to_roll_pitch_yaw => quat_to_rpy

  • private pure subroutine quat_to_rpy(q, roll, pitch, yaw)

    Converts the quaternion to the equivalent Euler angles of roll, pitch, and yaw.

    Arguments

    Type IntentOptional Attributes Name
    class(quaternion), intent(in) :: q

    The quaternion.

    real(kind=real64), intent(out) :: roll

    The roll angle (rotation about the body x-axis), in radians.

    real(kind=real64), intent(out) :: pitch

    The pitch angle (rotation about the body y-axis), in radians.

    real(kind=real64), intent(out) :: yaw

    The yaw angle (rotation about the body z-axis), in radians.